package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Administrator on 2019/7/8.
 */
@Service
public class TravelCommendServiceImpl implements ITravelCommendService{
    @Autowired
    private TravelCommendMapper travelCommendMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if (travelCommend.getId()==null){
            travelCommendMapper.insert(travelCommend);
        }else {
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    @Override
    public void delete(Long id) {
        travelCommendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public TravelCommend get(Long rid) {
        return travelCommendMapper.selectByPrimaryKey(rid);
    }

    @Override
    public List<TravelCommend> listAll() {
        return travelCommendMapper.selectAll();
    }

    @Override
    public List<TravelCommend> queryTop5() {
        return travelCommendMapper.selectTop5();
    }

}
